home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Hackers Handbook - Millenium Edition
/
Hackers Handbook.iso
/
files
/
c_scripts
/
scanport-wr.perl
< prev
next >
Wrap
Text File
|
1998-12-05
|
2KB
|
99 lines
#!/usr/bin/perl
#############################################################
#
# ScanPort v1.0
# Written By: Samuel Sparling (sparling@slip.net)
#
# Copyright ⌐ 1998 Samuel Sparling
# All Rights Reserved.
#
# Thanks to gargan for the idea of a perl port scanner
#
# Tested on:
# Windows 95 w/ ActiveWare's perl for Win32 (perl 5.003_07)
# SunOS 5.6 w/ perl 5.004_04
# Red Hat Linux 5.1 w/ perl 5.004_04
#
#############################################################
#
use Socket;
print "ScanPort v1.0\n\n";
print "Host: ";
$remote=<STDIN>;
chop($remote) if $remote =~ /\n$/;
print "Start Port: ";
$start=<STDIN>;
chop($start) if $start =~ /\n$/;
print "Stop Port: ";
$stop=<STDIN>;
chop($stop) if $stop =~ /\n$/;
print "Log Session?(y/n)";
$yn=<STDIN>;
if($yn =~ /y/i)
{
$log = 1;
$logfile="$remote".".scan";
print "Log File [$logfile]: ";
$file=<STDIN>;
chop($file) if $file =~ /\n$/;
if($file ne "")
{
$logfile=$file;
}
open(LOG,">>$logfile") || die("Unable to write to $logfile!");
}
$time = localtime(time);
print "\nScanning ports $start to $stop on $remote at $time\n\n";
if($log == 1)
{
print LOG "\nScanning ports $start to $stop on $remote at $time\n\n";
}
$current=$start;
while($current < $stop)
{
&scan_port($current);
$current++;
}
$time = localtime(time);
print "\nFinished scan of $remote at $time\n";
if($log == 1)
{
print LOG "\nFinished scan of $remote at $time\n";
close(LOG);
}
sub scan_port
{
$port = shift(@_);
if ($port =~ /\D/) { $port = getservbyname($port, 'tcp'); }
die("No port specified.") unless $port;
$iaddr = inet_aton($remote) || die("Failed to find host: $remote");
$paddr = sockaddr_in($port, $iaddr);
$proto = getprotobyname('tcp');
socket(SOCK, PF_INET, SOCK_STREAM, $proto) || die("Failed to open socket: $!");
if(connect(SOCK, $paddr))# || die("Unable to connect: $!");
{
print "Listening on port: $port\n";
if($log == 1)
{
print LOG "Listening on port: $port\n";
}
}
close(SOCK);
}
exit;